package com.ouc.util.impl;

import com.ouc.util.UUIDGenerator;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @Name: UUIDGeneratorImpl
 * @Description:
 * @Author: Mr.Tong
 */
@Component
public class UUIDGeneratorImpl implements UUIDGenerator {

    @Override
    public String get16UUID() {
        // 1.最大支持1-9个集群机器部署
        int machineId = 1;
        // 2.生成uuid的hashCode值
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        // 3.有可能是负数
        if (hashCodeV < 0) {
            hashCodeV = -hashCodeV;
        }
        // 4.结果
        String value = machineId + String.format("%015d", hashCodeV);
        return value;
    }
}
